package br.com.gsa.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size;

import org.hibernate.annotations.IndexColumn;
import org.hibernate.validator.constraints.NotEmpty;


@Entity
@Table(name="CLIENTE", schema="APP")
@NamedQuery(
    name="findAllClientes",
    query="SELECT c FROM Cliente c"
)
public class Cliente implements Serializable {
	
	
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="ID_CLIENTE")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	@Column(name="NOME_CLIENTE", length=100)
	@Size(max=100)
	@NotEmpty(message ="Por favor informe o Nome.")
	private String nome;
	
	@Column(name="CNPJ_CLIENTE", length=15)
	@Size(max=15)
	private String cnpj;
	
	@Column(name="CPF_CLIENTE", length=11)
	@Size(max=11)
	private String cpf;
	
	@OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
	@JoinColumn(name="ID_CLIENTE")
	private List<ContatoCliente> contatos;
	
	
	
	
	@Transient
	private String status;
	
	@Transient
	private String tipoCliente;
	
	@OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
	@IndexColumn(name="ID_CLIENTE")
	private List<Endereco> enderecos;
	
	public Cliente(List<ContatoCliente> contatos, String nome, String cpf, String cnpj) {
		this.contatos = contatos;
		this.nome = nome;
		this.cpf =  cpf;
		this.cnpj = cnpj;
		
	}
	
	public Cliente() {
		// TODO Auto-generated constructor stub
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<ContatoCliente> getContatos() {
		return contatos;
	}

	public void setContatos(List<ContatoCliente> contatos) {
		this.contatos = contatos;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getCnpj() {
		return cnpj;
	}

	public void setCnpj(String cnpj) {
		this.cnpj = cnpj;
	}

	public String getCpf() {
		return cpf;
	}

	public void setCpf(String cpf) {
		this.cpf = cpf;
	}

	
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	
	public String getTipoCliente() {
		return tipoCliente;
	}

	public void setTipoCliente(String tipoCliente) {
		this.tipoCliente = tipoCliente;
	}


	public List<Endereco> getEnderecos() {
		return enderecos;
	}

	public void setEnderecos(List<Endereco> enderecos) {
		this.enderecos = enderecos;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result	+ ((id == null) ? 0 : id.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Cliente other = (Cliente) obj;
		if (id == null) {
			if (other.id!= null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
